'''
Description: 
Autor: didiplus
Date: 2023-01-13 14:48:04
LastEditors: lin
LastEditTime: 2023-01-13 14:56:37
'''

import math
from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor
import time

num_list = [112272535095293] * 100

def is_prime(num):

    """
    判断是不是素数
    """
    if num < 2:
        return False
    
    if num == 2:
        return True
    
    if num % 2 == 0:
        return False
    sqrt_n  = int(math.floor(math.sqrt(num)))

    for i in range(3,sqrt_n+1,2):
        if num % i == 0:
            return False
    return True

# 单线程
def single_thread():
    for num in num_list:
        is_prime(num)

#多线程
def multi_thread():
    with ThreadPoolExecutor() as pool:
        pool.map(is_prime,num_list)

# 多进程
def multi_process():
    with ProcessPoolExecutor() as pool:
        pool.map(is_prime,num_list)

if __name__ == "__main__":
    start = time.time()
    single_thread()
    end = time.time()
    print('单线程：', end - start, '秒')

    start = time.time()
    multi_thread()
    end = time.time()
    print('多线程：', end - start, '秒')


    start = time.time()
    multi_process()
    end = time.time()
    print('多进程', end - start, '秒')    
